package com.hotel.company.service;

import com.hotel.comm.bean.DubboReply;
import com.hotel.comm.bean.IReply;
import com.hotel.comm.bean.company.EJobCompanyComment;
import com.hotel.comm.service.company.ICompanyCommentService;
import com.hotel.company.Constants;
import com.hotel.company.repository.IEjobCompanyCommentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 企业评价service层
 * Created by frank on 15-6-16.
 */
@Service
public class CompanyCommentServiceImpl implements ICompanyCommentService {

    @Autowired
    IEjobCompanyCommentRepository ejobCompanyCommentRepository;

    @Override
    public IReply getById(Long companyCommentId) {
        try {
            EJobCompanyComment eJobCompanyComment = this.ejobCompanyCommentRepository.findOne(companyCommentId);
            return new DubboReply(eJobCompanyComment);
        } catch (Exception e) {
            return new DubboReply(Constants.REPLY_CODE_COMPANY_COMMENT_GET_BY_ID, Constants.REPLY_MSG_COMPANY_COMMENT_GET_BY_ID);
        }
    }

    @Override
    public IReply saveOrUpdate(EJobCompanyComment eJobCompanyComment) {
        try {
            EJobCompanyComment companyComment = this.ejobCompanyCommentRepository.save(eJobCompanyComment);
            return new DubboReply(companyComment);
        } catch (Exception e) {
            return new DubboReply(Constants.REPLY_CODE_SAVE_COMPANY_COMMENT, Constants.REPLY_MSG_SAVE_COMPANY_COMMENT);
        }
    }

    @Override
    public IReply delete(Long companyCommentId) {
        try {
            this.ejobCompanyCommentRepository.delete(companyCommentId);
            return new DubboReply(ejobCompanyCommentRepository);
        } catch (Exception e) {
            return new DubboReply(Constants.REPLY_CODE_DELETE_COMPANY_COMMENT, Constants.REPLY_MSG_DELETE_COMPANY_COMMENT);
        }
    }
}
